package com.aaa.system.controller;

import com.aaa.common.pojo.Role;
import com.aaa.common.vo.Result;
import com.aaa.system.Person;
import com.aaa.system.service.RoleService;
import com.aaa.system.vo.RoleVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @program: education-parent
 * @description:
 * @author: 闫克起2
 * @create: 2023-05-24 16:25
 **/
@RestController
@RequestMapping("system/role")
public class RoleController {

    @Autowired
    private RoleService roleService;


    @GetMapping("/getByUserId/{userId}")
    public Result getByUserId(@PathVariable String userId){
        List<Role> all = roleService.findAll();
        List<Role> roles = roleService.findByUserId(userId);
        List<String> roleids = roles.stream().map(item -> item.getId()).collect(Collectors.toList());
        Map<String,Object> map=new HashMap<>();
        map.put("all",all);
        map.put("roles",roleids);
        return Result.success(map);
    }
    @PostMapping("confirm")
    @ApiOperation("确认分配角色")
    public Result confirm(String userId,String[] roleIds){
        Integer row=roleService.confirm(userId,roleIds);
        return Result.success();
    }


    @PostMapping("list/{current}/{pageSize}")
    @ApiOperation(value = "分页条件查询角色")
    public Result list(@PathVariable Integer current,@PathVariable Integer pageSize,@RequestBody RoleVo roleVo){
        Page<Role> page= roleService.list(current,pageSize,roleVo);
        return Result.success(page);
    }


}
